#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"

#define BP 10

int main( int argc, char *argv[] )
{
	int i, fd;
	if ( argc <= 1 )
	{
		printf( 1, "no argc\n" );
		exit();
	}
	int filenum = atoi( argv[1] );
	if ( filenum > 1000 )
	{
		printf( 1, "to mach testfile\n" );
		exit();
	}

	printf( 1, "------test large file write------\n" );

	int	start, end;
	char	str[512];
	for ( i = 0; i < 512; i++ )
	{
		str[i] = 'a';
	}
	char filename[5];

	printf( 1, "------make test file------\n" );

	start = uptime();

	for ( i = 0; i < filenum; i++ )
	{
        itoa(i,filename);
        //printf(1,"%s\n",filename);
        if ( (fd = open( filename, O_WRONLY | O_CREATE ) ) < 0 )
		{
			printf( 1, "test: cannot open %d: %s\n", i, filename );
			exit();
		}
		for ( int ii = 0; ii < BP; ii++ )
			write( fd, str, 512 );
        close(fd);
	}
	/* sleep(100); */

	end = uptime();
    int time=end-start;
    double a=(double)time/(double)filenum;
    int a1=a*10000/10000;
    int a2=((int)(a*10000))%10000;
    //printf(1,"%d\n",(int)(a*10000));
	printf( 1, "write time total: %d, avg: %d.%d\n", time, a1, a2);
  
	exit();
}